# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=vala
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.56.13
pkgrel=1
pkgdesc="Compiler for the GObject type system (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
url="https://wiki.gnome.org/Projects/Vala"
license=("LGPL")
makedepends=("help2man"
             "${MINGW_PACKAGE_PREFIX}-libxslt"
             "${MINGW_PACKAGE_PREFIX}-autotools"
             "${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-vala")
depends=("${MINGW_PACKAGE_PREFIX}-glib2"
         "${MINGW_PACKAGE_PREFIX}-graphviz")
source=(https://download.gnome.org/sources/${_realname}/${pkgver%.*}/${_realname}-${pkgver}.tar.xz
        0001-relocate-plugin-path.patch)
sha256sums=('4988223036c7e1e4874c476d0de8bd9cbe500ee25ef19a76e560dc0b6d56ae07'
            '266756afe0fa2871800e2d4cbf5db5c9e9e68abd52f7f694f077c7e425bc2772')

prepare() {
  cd "${srcdir}"/${_realname}-${pkgver}

  # https://gitlab.gnome.org/GNOME/vala/-/issues/1302
  patch -p1 -i "${srcdir}/0001-relocate-plugin-path.patch"

  autoreconf -ivf
}

build() {
  [[ -d "${srcdir}/build-${MSYSTEM}" ]] && rm -rf "${srcdir}/build-${MSYSTEM}"
  mkdir -p "${srcdir}/build-${MSYSTEM}" && cd "${srcdir}/build-${MSYSTEM}"

  CFLAGS+=" -Wno-incompatible-pointer-types" \
  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --enable-shared

  make
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"
  make DESTDIR="${pkgdir}" install

  # Move libvalaccodegen.dll to correct directory
  mv "${pkgdir}${MINGW_PREFIX}"/lib/bin/libvalaccodegen.dll "${pkgdir}${MINGW_PREFIX}"/bin/libvalaccodegen.dll
  rm -rf "${pkgdir}${MINGW_PREFIX}"/lib/bin

  install -Dm644 "${srcdir}/${_realname}-${pkgver}/COPYING" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING"
}
